package com.dwxt.cdms.util;

import cn.hutool.core.io.resource.BytesResource;

public class EcgUtil {

    public static BytesResource Ecg2BytesResource(String data) {
        byte[] bytes = data.getBytes();
        int length = bytes.length;
        byte [] arr=new byte[length/2];
        for (int i = 0; i < bytes.length; i += 2) {
            byte b = (byte) (charToInt(bytes[i]) * 16 + charToInt(bytes[i + 1]));
            arr[i / 2] = b;
        }

        return new BytesResource(arr,"ecg");
    }

    private static int charToInt(byte ch) {
        int val = 0;
        if (ch >= 0x30 && ch <= 0x39) {
            val = ch - 0x30;
        } else if (ch >= 0x41 && ch <= 0x46) {
            val = ch - 0x41 + 10;
        }
        return val;
    }
}
